package com.ljn.service.imp;

import com.ljn.core.dto.common.User;
import com.ljn.core.dto.common.utils.ency.MD5EncryptUtil;
import com.ljn.mapper.UserMapper;
import com.ljn.service.UserService;

import javax.inject.Inject;
import javax.inject.Named;

/**
 * Created by liujunnan on 2017/11/2.
 */
@Named
public class UserServiceImpl implements UserService {
    @Inject
    UserMapper userMapper;

    private User findByUsername(String userName) {

        return userMapper.findUserByUsername(userName);
    }


    @Override
    public int register(User user) {
        return 0;
    }

    @Override
    public User login(User user) {
            User result = userMapper.selectByEntity(user);
        if (result.getPassword().equals(MD5EncryptUtil.encryptPassword(user.getPassword(), result.getUserId()))) {
            return userMapper.selectByEntity(user);
        }
        return null;    }

    @Override
    public boolean changeUserPwd(User user) {
        return this.userMapper.updateByPrimaryKeySelective(user) > 0 ? true:false;
    }

    @Override
    public User findUserByCond(User user) {
        return userMapper.findUserByCond(user);
    }
}